package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.CallOrderMobileRecord;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.CallOrderMobileRecordMapper;
import com.zrwl.poscloud.xo.service.CallOrderMobileRecordService;
import com.zrwl.poscloud.xo.vo.CallOrderMobileRecordVO;

import javax.annotation.Resource;

/**
 * 订单绑定电话记录 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-06-09
 */
@Service
public class CallOrderMobileRecordServiceImpl extends SuperServiceImpl<CallOrderMobileRecordMapper,CallOrderMobileRecord> implements CallOrderMobileRecordService {

    @Autowired
    private CallOrderMobileRecordService callOrderMobileRecordService;
    @Resource
    private CallOrderMobileRecordMapper callOrderMobileRecordMapper;
    @Override
    public IPage<CallOrderMobileRecord> getPageList(CallOrderMobileRecordVO callOrderMobileRecordVO){
       QueryWrapper<CallOrderMobileRecord> queryWrapper = new QueryWrapper<>();
       if (StringUtils.isNotEmpty(callOrderMobileRecordVO.getKeyword()) && !StringUtils.isEmpty(callOrderMobileRecordVO.getKeyword().trim())) {
            queryWrapper.like("name", callOrderMobileRecordVO.getKeyword().trim());
       }
       Page<CallOrderMobileRecord> page = new Page<>();
       page.setCurrent(callOrderMobileRecordVO.getCurrentPage());
       page.setSize(callOrderMobileRecordVO.getPageSize());
       queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
       queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
       IPage<CallOrderMobileRecord> pageList = callOrderMobileRecordService.page(page, queryWrapper);
       List<CallOrderMobileRecord> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<CallOrderMobileRecordVO> getAllList(CallOrderMobileRecordVO callOrderMobileRecordVO){
        List<CallOrderMobileRecordVO> list = callOrderMobileRecordMapper.getCallOrderMobilelist(callOrderMobileRecordVO);
        return list;
}
    @Override
    public String add(CallOrderMobileRecordVO callOrderMobileRecordVO){
        CallOrderMobileRecord entity = new CallOrderMobileRecord();
        BeanUtils.copyProperties(callOrderMobileRecordVO, entity, SysConf.STATUS);
        entity.insert();
        callOrderMobileRecordVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(CallOrderMobileRecordVO callOrderMobileRecordVO){
        CallOrderMobileRecord entity = callOrderMobileRecordService.getById(callOrderMobileRecordVO.getUid());
        BeanUtils.copyProperties(callOrderMobileRecordVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(CallOrderMobileRecordVO callOrderMobileRecordVO){
        CallOrderMobileRecord entity = callOrderMobileRecordService.getById(callOrderMobileRecordVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
